using System;
using Actions;
using TMPro;
using UnityEngine;

namespace UI
{
    public class ScoreUi : MonoBehaviour
    {
        [SerializeField] private Shooter shooter;
        
        private TextMeshProUGUI _text;

        private int _score;


        private void Awake()
        {
            _text = GetComponent<TextMeshProUGUI>();
        }

        private void OnEnable()
        {
            shooter.AnyTargetDied += Shooter_AnyTargetDied;
        }

        private void OnDisable()
        {
            shooter.AnyTargetDied -= Shooter_AnyTargetDied;
        }

        private void Shooter_AnyTargetDied()
        {
            _score++;
            _text.text = _score.ToString();
        }
    }
}
